def fall(inntak):
	strengir = []
	strengir2 = []
	strengir3 = []
	strengir4 = []
	strengir5 = []
	strengir6 = []
	strengir7 = []
	strengir8 = []
	strengir9 = []
	if inntak == 1:
		return 0
	for x in range(inntak):
		for y in range(inntak):
			strengir.append(str(x) + str(y))
	
	for x in range(len(strengir)):
		if strengir[x][0] != strengir[x][1]:
			strengir2.append(strengir[x])
		if len(strengir2) != 0:
			lausn = len(strengir2)
	
	if len(strengir2) != 0:
		for x in range(len(strengir2)):
			if strengir2[x][0] != strengir2[0][0] and strengir2[x][1] != strengir2[0][1]:
				strengir3.append(strengir2[x])
		if len(strengir3) != 0:
			lausn *= len(strengir3)
	
	if len(strengir3) != 0:
		for x in range(len(strengir3)):
			if strengir3[x][0] != strengir3[0][0] and strengir3[x][1] != strengir3[0][1]:
				strengir4.append(strengir3[x])
		if len(strengir4) != 0:
			lausn *= len(strengir4)
	
	if len(strengir4) != 0:
		for x in range(len(strengir4)):
			if strengir4[x][0] != strengir4[0][0] and strengir4[x][1] != strengir4[0][1]:
				strengir5.append(strengir4[x])
		if len(strengir5) != 0:
			lausn *= len(strengir5)

	if len(strengir5) != 0:
		for x in range(len(strengir5)):
			if strengir5[x][0] != strengir5[0][0] and strengir5[x][1] != strengir5[0][1]:
				strengir6.append(strengir5[x])
		if len(strengir6) != 0:
			lausn *= len(strengir6)
		
	if len(strengir6) != 0:
		for x in range(len(strengir6)):
			if strengir6[x][0] != strengir6[0][0] and strengir6[x][1] != strengir6[0][1]:
				strengir7.append(strengir6[x])
		if len(strengir7) != 0:
			lausn *= len(strengir7)

	if len(strengir7) != 0:
		for x in range(len(strengir7)):
			if strengir7[x][0] != strengir7[0][0] and strengir7[x][1] != strengir7[0][1]:
				strengir8.append(strengir7[x])
		if len(strengir8) != 0:
			lausn *= len(strengir8)
		
	if len(strengir8) != 0:
		for x in range(len(strengir8)):
			if strengir8[x][0] != strengir8[0][0] and strengir8[x][1] != strengir8[0][1]:
				strengir9.append(strengir8[x])
		if len(strengir9) != 0:
			lausn *= len(strengir9)
	return lausn
	
profanir = int(input())

tilvik = []
for x in range(profanir):
	tala = int(input())
	tilvik.append(tala)
	print(fall(tala))
